import BreadStore from "@/common/stores/BreadStore";

function emptyAction(...args) {
  console.warn("Current execute action is empty!");
}

class Actions {

  action = {
    onGlobalStateChange: emptyAction,
    setGlobalState: emptyAction,
    sendMessage2MainApp: emptyAction
  };

  /**
   * 设置 actions
   */
  setActions(actions) {
    this.action = actions;
  }

  onGlobalStateChange() {
    this.action.onGlobalStateChange((state: any, prevState: any) => {
      // state: 变更后的状态; prev 变更前的状态
      console.log('--------------onGlobalStateChange-------------');
      console.log(state, prevState);
      BreadStore.setCurrentMenus(state.currentMenus);
    });
  }

  /**
   * 子应用直接调用 setGlobalState 是不生效的, 所以才需要这个额外的方法
   */
  sendMessage2MainApp(state) {
    return this.action.sendMessage2MainApp(state);
  }
}

const actions = new Actions();
export default actions;

